package com.htfyun.factorytest.factorytestui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.ContextThemeWrapper;
import android.view.EinkPWInterface;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.ScreenUtils;
import com.htfyun.eink.EinkShowMode;
import com.htfyun.eink.EinkUtils;
import com.htfyun.factorytest.BuildConfig;
import com.htfyun.factorytest.R;
import com.htfyun.factorytest.RootApplication;
import com.htfyun.factorytest.device.DeviceAttr;
import com.htfyun.factorytest.utils.DebugLog;

import java.lang.reflect.Method;
import java.util.ArrayList;

public class FactorySecondActivity extends FactoryBaseActivity {
    private RelativeLayout parentContainer;
    private static final int DIAGONAL_LINE_RADIUS = 80;
    private static final int GRID_COL_NUM = 9;
    private static final int GRID_ROW_NUM = 13;
    public boolean isTouched = false;
    public float mCellHeight;
    public float mCellWidth;
    public Grid mGrid;
    public DiagonalLine mLine1;
    public DiagonalLine mLine2;

    private boolean isETP = false;
    private TextView txtInfo;
    private ImageView imgUseTool;
    private int layoutWidth = 1404;
    private int layoutHeight = 1872;

    enum MarkedState {
        None,
        Old,
        New
    }

    private static final int COLOR_FILL = Color.BLACK;
    private static final int COLOR_FRAME = Color.BLACK;
    private static final int COLOR_CLEAR = Color.WHITE;

    private EinkPWInterface einkPWInterface;

    private class Grid {
        private static final float STROKE_WIDTH_FRAME = 2.0f;
        public float mCellHeight;
        //        private int mCellMarkedNum;
        public float mCellWidth;
        private final ArrayList<Cell> mList = new ArrayList<>();
        public final Paint mPaintFill = new Paint();
        public final Paint mPaintFrame = new Paint();
        private boolean mTouched;
//        private float mX;
//        private float mY;

        private class Cell {
            private int mCol;
            private boolean mMarked = false;
            private int mRow;

            private Cell(int row, int col) {
                mCol = col;
                this.mRow = row;
            }

            private void fill(Canvas canvas) {
                float x1 = mCellWidth * ((float) this.mCol);
                float y1 = mCellHeight * ((float) this.mRow);
                float x2 = x1 + mCellWidth;
                float y2 = y1 + mCellHeight;
                if (this.mMarked) {
                    canvas.drawRect(x1, y1, x2, y2, mPaintFill);
                }
            }

            private void draw(Canvas canvas) {
                float x1 = mCellWidth * ((float) this.mCol);
                float y1 = mCellHeight * ((float) this.mRow);
                float x2 = x1 + mCellWidth;
                float y2 = y1 + mCellHeight;
                canvas.drawLine(x1, y1, x1, y2, mPaintFrame);
                canvas.drawLine(x1, y1, x2, y1, mPaintFrame);
                canvas.drawLine(x1, y2, x2, y2, mPaintFrame);
                canvas.drawLine(x2, y1, x2, y2, mPaintFrame);
            }

            private boolean getMarked() {
                return mMarked;
            }

            private void setMarked(boolean value) {
                mMarked = value;
            }

            private boolean test(int row, int col) {
                return row == mRow && col == mCol;
            }
        }

        Grid(float cellWidth, float cellHeight) {
            mCellWidth = cellWidth;
            mCellHeight = cellHeight;
//            mCellMarkedNum = 0;
            mTouched = false;
            init();
        }

        private void init() {
            mPaintFrame.setAntiAlias(false);
            mPaintFrame.setStrokeWidth(STROKE_WIDTH_FRAME);
            mPaintFrame.setDither(true);
            mPaintFrame.setStyle(Paint.Style.STROKE);
            mPaintFrame.setColor(COLOR_FRAME);
            mPaintFill.setAntiAlias(false);
            mPaintFill.setDither(true);
            mPaintFill.setStyle(Paint.Style.FILL);
            mPaintFill.setColor(COLOR_FILL);
        }

        private MarkedState mark(float x, float y) {
            Cell cell = findCell((int) (y / mCellHeight), (int) (x / mCellWidth));
            if (cell == null) {
                return MarkedState.None;
            }
            if (cell.getMarked()) {
                return MarkedState.Old;
            }
            cell.setMarked(true);
            mList.remove(cell);
//            mCellMarkedNum++;
            return MarkedState.New;
        }

        private void fill(Canvas canvas) {
            int len = mList.size();
            for (int i = 0; i < len; i++) {
                mList.get(i).fill(canvas);
            }
//            canvas.drawPath(mPath, mPaintPath);
        }

        private void draw(Canvas canvas) {
            int len = mList.size();
            for (int i = 0; i < len; i++) {
                mList.get(i).draw(canvas);
            }
//            canvas.drawPath(mPath, mPaintPath);
        }

        Cell findCell(int row, int col) {
            int len = mList.size();
            for (int i = 0; i < len; i++) {
                Cell cell = mList.get(i);
                if (cell.test(row, col)) {
                    return cell;
                }
            }
            return null;
        }

        public Cell add(int row, int col) {
            Cell cell = findCell(row, col);
            if (cell == null) {
                Cell cell2 = new Cell(row, col);
                mList.add(cell2);
                return cell2;
            }
            return cell;
        }

        boolean touchDown(float x, float y) {
            if (isFinished()) {
                return false;
            }
            MarkedState markedstate = mark(x, y);
            if (markedstate != MarkedState.New && markedstate != MarkedState.Old) {
                return false;
            }
//            mPath.moveTo(x, y);
//            mX = x;
//            mY = y;
            mTouched = true;
            return true;
        }

        boolean touchMove(float x, float y) {
            if (isFinished()) {
                return false;
            }
            MarkedState markedstate = mark(x, y);
            if (markedstate == MarkedState.New || markedstate == MarkedState.Old) {
                if (!mTouched) {
                    mTouched = true;
                }
                return true;
            } else if (markedstate == MarkedState.None) {
                return clear();
            } else {
                return false;
            }
        }

        boolean touchUp() {
            return clear();
        }

        public boolean clear() {
            if (!mTouched) {
                return false;
            }
//            mPath.rewind();
            mTouched = false;
            return true;
        }

        boolean isFinished() {
//            return mList.size() == mCellMarkedNum;
            return mList.size() == 0;
        }

        void reset() {
//            mCellMarkedNum = 0;
//            mPath.reset();
        }
    }

    public class DiagonalLine {
        private static final float POINT_CROSS_SIZE = 18.0f;
        private static final float POINT_TEST_Y_TOLERANT = 60.0f;
        private static final float STROKE_WIDTH_FRAME = 2.0f;
        private Paint mPaintFill = new Paint();
        private Paint mPaintFrame = new Paint();
        private boolean mPoint1Marked;
        private boolean mPoint2Marked;
        private boolean mPoint3Marked;
        private boolean mPoint4Marked;
        private boolean mPoint5Marked;
        private float mPointTestYTolerant;
        private float mR;
        private boolean mTouched;
        //        private float mX;
        private float mX1;
        private float mX2;
        //        private float mY;
        private float mY1;
        private float mY2;
        private float old_x;
        private float old_y;

        DiagonalLine(float x1, float y1, float x2, float y2, float r) {
            mX1 = x1;
            mY1 = y1;
            mX2 = x2;
            mY2 = y2;
            mR = r;
            mPointTestYTolerant = POINT_TEST_Y_TOLERANT;
            mPoint1Marked = false;
            mPoint2Marked = false;
            mPoint3Marked = false;
            mPoint4Marked = false;
            mPoint5Marked = false;
            old_x = 0.0f;
            old_y = 0.0f;
            init();
        }

        private void init() {
            mPaintFrame.setAntiAlias(true);
            mPaintFrame.setStrokeWidth(STROKE_WIDTH_FRAME);
            mPaintFrame.setDither(true);
            mPaintFrame.setStyle(Paint.Style.STROKE);
            mPaintFrame.setColor(COLOR_FRAME);
            mPaintFill.setAntiAlias(false);
            mPaintFill.setStrokeWidth(1.0f);
            mPaintFill.setDither(true);
            mPaintFill.setStyle(Paint.Style.STROKE);
            mPaintFill.setColor(COLOR_FILL);
        }

        void fill(Canvas canvas) {
            if (isFinished()) {
                float x = -mR;
                while (true) {
                    x += 1.0f;
                    if (x < mR) {
                        canvas.drawLine(mX1 + x, mY1, mX2 + x, mY2, mPaintFill);
                    } else {
                        return;
                    }
                }
            }
        }

        private void drawCross(Canvas canvas, float x, float y) {
            canvas.drawLine(x - POINT_CROSS_SIZE, y - POINT_CROSS_SIZE, x + POINT_CROSS_SIZE, y + POINT_CROSS_SIZE, mPaintFrame);
            canvas.drawLine(x + POINT_CROSS_SIZE, y - POINT_CROSS_SIZE, x - POINT_CROSS_SIZE, y + POINT_CROSS_SIZE, mPaintFrame);
        }

        void drawFrame(Canvas canvas, int color) {
            mPaintFrame.setColor(color);
            canvas.drawLine(mX1 - mR, mY1, mX2 - mR, mY2, mPaintFrame);
            canvas.drawLine(mX1 + mR, mY1, mX2 + mR, mY2, mPaintFrame);
            drawCross(canvas, mX1 + (((mX2 - mX1) * mPointTestYTolerant) / (mY2 - mY1)), mY1 + mPointTestYTolerant);
            drawCross(canvas, mX2 - (((mX2 - mX1) * mPointTestYTolerant) / (mY2 - mY1)), mY2 - mPointTestYTolerant);
        }

        boolean testInRange(float x, float y) {
            if (mY1 <= y) {
                if (y <= mY2) {
                    float x0 = (((mX2 - mX1) * (y - mY1)) / (mY2 - mY1)) + mX1;
//                    DebugLog.d("DiagonalLine.testInRange : x0=" + x0 + ", x=" + x + ", y=" + y);
                    return Math.abs(x - x0) < mR;
                }
            }
            return false;
        }

        private boolean testInPoint1(float x, float y) {
            if (y >= mY1 + mCellHeight) {
                return false;
            }
            float x_ = mX1 + (((y - mY1) * (mX2 - mX1)) / (mY2 - mY1));
//            DebugLog.d("DiagonalLine.testInPoint1 : x_=" + x_ + ",x=" + x);
            return Math.abs(x - x_) < mR;
        }

        private boolean testInPoint2(float x, float y) {
            if (y <= mY2 - mCellHeight) {
                return false;
            }
            float x_ = mX2 + (((y - mY2) * (mX2 - mX1)) / (mY2 - mY1));
//            DebugLog.d("DiagonalLine.testInPoint2 : x_=" + x_ + ",x=" + x);
            return Math.abs(x - x_) < mR;
        }

        private boolean testInPoint3(float x, float y) {
            if (y <= ((mY1 + mY2) / STROKE_WIDTH_FRAME) - mCellHeight || y >= ((mY1 + mY2) / STROKE_WIDTH_FRAME) + mCellHeight) {
                return false;
            }
            float x_ = ((mX1 + mX2) / STROKE_WIDTH_FRAME) + (((y - ((mY1 + mY2) / STROKE_WIDTH_FRAME)) * (mX2 - mX1)) / (mY2 - mY1));
//            DebugLog.d("DiagonalLine.testInPoint3 : x_=" + x_ + ",x=" + x);
            return Math.abs(x - x_) < mR;
        }

        private boolean testInPoint4(float x, float y) {
            float h = mCellHeight;
            float f = mY1;
            float f2 = mY2;
            if (y <= ((f + f2) / 4.0f) - h || y >= ((f + f2) / 4.0f) + h) {
                return false;
            }
            float f3 = mX1;
            float f4 = mX2;
            float x_ = ((f3 + f4) / STROKE_WIDTH_FRAME) + (((y - ((f + f2) / STROKE_WIDTH_FRAME)) * (f4 - f3)) / (f2 - f));
//            DebugLog.d("DiagonalLine.testInPoint4 : x_=" + x_);
            return Math.abs(x - x_) < mR;
        }

        private boolean testInPoint5(float x, float y) {
            float h = mCellHeight;
            float f = mY1;
            float f2 = mY2;
            if (y <= (((f + f2) * 3.0f) / 4.0f) - h || y >= (((f + f2) * 3.0f) / 4.0f) + h) {
                return false;
            }
            float f3 = mX1;
            float f4 = mX2;
            float x_ = ((f3 + f4) / STROKE_WIDTH_FRAME) + (((y - ((f + f2) / STROKE_WIDTH_FRAME)) * (f4 - f3)) / (f2 - f));
//            DebugLog.d("DiagonalLine.testInPoint5 : x_=" + x_);
            return Math.abs(x - x_) < mR;
        }

        void testMarked(float x, float y) {
            if (!mPoint1Marked && testInPoint1(x, y)) {
//                DebugLog.d("DiagonalLine.touchDown : mPoint1Marked");
                mPoint1Marked = true;
            } else if (!mPoint2Marked && testInPoint2(x, y)) {
//                DebugLog.d("DiagonalLine.touchDown : mPoint2Marked");
                mPoint2Marked = true;
            } else if (!mPoint3Marked && testInPoint3(x, y)) {
//                DebugLog.d("DiagonalLine.touchDown : mPoint3Marked");
                mPoint3Marked = true;
            } else if (!mPoint4Marked && testInPoint4(x, y)) {
//                DebugLog.d("DiagonalLine.touchDown : mPoint4Marked");
                mPoint4Marked = true;
            } else if (!mPoint5Marked && testInPoint5(x, y)) {
//                DebugLog.d("DiagonalLine.touchDown : mPoint5Marked");
                mPoint5Marked = true;
            }
        }

        boolean touchDown(float x, float y) {
            if (isFinished()) {
                return false;
            }
            testMarked(x, y);
            if (!isTouched()) {
                return false;
            }
//            DebugLog.d("DiagonalLine.touchDown : x=" + x + ",y=" + y);
            mTouched = true;
            if (x != old_x) {
                old_x = x;
            }
            if (y != old_y) {
                old_y = y;
            }
            return true;
        }

        boolean touchMove(float x, float y) {
            if (isFinished()) {
                return false;
            }
            Math.abs(y - old_y);
            if (!isTouched() || !testInRange(x, y)) {
                return clear();
            }
//            DebugLog.d("DiagonalLine.touchMove : x=" + x + ",y=" + y);
            testMarked(x, y);
            if (x != old_x) {
                old_x = x;
            }
            if (y != old_y) {
                old_y = y;
            }
            if (!isFinished()) {
                return true;
            }
            return true;
        }

        boolean touchUp() {
            return clear();
        }

        public boolean clear() {
            if (!mTouched) {
                return false;
            }
//            mPath.rewind();
            if (!isFinished()) {
                mPoint1Marked = false;
                mPoint2Marked = false;
                mPoint3Marked = false;
                mPoint4Marked = false;
                mPoint5Marked = false;
            }
            mTouched = false;
            return true;
        }

        boolean isFinished() {
            return mPoint1Marked && mPoint2Marked && mPoint3Marked && mPoint4Marked && mPoint5Marked;
        }

        boolean isTouched() {
            return mPoint1Marked || mPoint2Marked || mPoint3Marked || mPoint4Marked || mPoint5Marked;
        }

        void reset() {
            mPoint1Marked = false;
            mPoint2Marked = false;
            mPoint3Marked = false;
            mPoint4Marked = false;
            mPoint5Marked = false;

//            mPath.reset();

        }
    }

    public class TouchPanelView extends View {

        public TouchPanelView(Context context) {
            super(context);
            init();
        }

        public TouchPanelView(Context context, int width, int height) {
            super(context);
            init(width, height);
        }

        @Override
        public void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            drawBg(canvas);
//            DebugLog.e("drawBg");
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (!isTouched) {
                isTouched = true;
            }

//            if (event.getPointerCount() == 1 && event.getToolType(0) ==
            if (event.getToolType(0) ==
                    (isETP ? MotionEvent.TOOL_TYPE_STYLUS : MotionEvent.TOOL_TYPE_FINGER)) {
                return processEvent(event);
            } else
                return super.onTouchEvent(event);

        }

        private void init() {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
            int mWidthPixels = displayMetrics.widthPixels;
            int mHeightPixels = displayMetrics.heightPixels;
            float cellWidth = ((float) mWidthPixels) / GRID_COL_NUM;
            float cellHeight = ((float) mHeightPixels) / GRID_ROW_NUM;
            mCellWidth = cellWidth;
            mCellHeight = cellHeight;
            mGrid = new Grid(cellWidth, cellHeight);
            addGrids();
            mLine1 = new DiagonalLine(0.0f, 0.0f, (float) mWidthPixels, (float) mHeightPixels, DIAGONAL_LINE_RADIUS);
            mLine2 = new DiagonalLine((float) mWidthPixels, 0.0f, 0.0f, (float) mHeightPixels, DIAGONAL_LINE_RADIUS);
        }

        private void init(int width, int height) {
            float cellWidth = ((float) width) / GRID_COL_NUM;
            float cellHeight = ((float) height) / GRID_ROW_NUM;
            mCellWidth = cellWidth;
            mCellHeight = cellHeight;
            mGrid = new Grid(cellWidth, cellHeight);
            addGrids();
            mLine1 = new DiagonalLine(0.0f, 0.0f, (float) width, (float) height, DIAGONAL_LINE_RADIUS);
            mLine2 = new DiagonalLine((float) width, 0.0f, 0.0f, (float) height, DIAGONAL_LINE_RADIUS);
        }

        private void addGrids() {
            for (int col = 0; col < GRID_COL_NUM; col++) {
                mGrid.add(0, col);
                mGrid.add(GRID_ROW_NUM - 1, col);
            }
            for (int row = 1; row < GRID_ROW_NUM - 1; row++) {
                mGrid.add(row, 0);
                mGrid.add(row, GRID_COL_NUM - 1);
            }
        }

        public void drawBg(Canvas canvas) {
            canvas.drawColor(Color.WHITE);

//            DebugLog.e("drawBg");
//            mGrid.fill(canvas);
//            mLine1.fill(canvas);
//            mLine2.fill(canvas);

            mGrid.draw(canvas);
            mLine1.drawFrame(canvas, COLOR_FRAME);
            mLine2.drawFrame(canvas, COLOR_FRAME);
//            DebugLog.e("drawBg");
            if (mLine1.isFinished()) {
                mLine1.drawFrame(canvas, COLOR_CLEAR);
            }
            if (mLine2.isFinished()) {
                mLine2.drawFrame(canvas, COLOR_CLEAR);
            }
        }

        private boolean processEvent(MotionEvent event) {
            float x = event.getX();
            float y = event.getY();

            int action = event.getAction();
            /*if (action != MotionEvent.ACTION_DOWN) {
                if (action != MotionEvent.ACTION_UP) {
                    if (action == MotionEvent.ACTION_MOVE) {
                        if ((mGrid.touchMove(x, y) | mLine1.touchMove(x, y)) || mLine2.touchMove(x, y)) {
                            invalidate();
                            testFinished();
                        }
                        return true;
                    } else if (action != MotionEvent.ACTION_CANCEL) {
                        return false;
                    }
                }
                if ((mGrid.touchUp() | mLine1.touchUp()) || mLine2.touchUp()) {
                    invalidate();
                }
                return true;
            }
            if ((mGrid.touchDown(x, y) | mLine1.touchDown(x, y)) || mLine2.touchDown(x, y)) {
                invalidate();
                testFinished();
            }*/
            if (action == MotionEvent.ACTION_DOWN) {
                if ((mGrid.touchDown(x, y) | mLine1.touchDown(x, y) | mLine2.touchDown(x, y))) {
                    invalidate();
                    testFinished();
                }
            } else if (action == MotionEvent.ACTION_MOVE) {
                if ((mGrid.touchMove(x, y) | mLine1.touchMove(x, y) | mLine2.touchMove(x, y))) {
//                    invalidate(EINK_SHOW_MODE_GL);
                    testFinished();
                }
                return true;
            } else if (action == MotionEvent.ACTION_UP) {
                if ((mGrid.touchUp() | mLine1.touchUp() | mLine2.touchUp())) {
                    invalidate();
                }
            } else return action != MotionEvent.ACTION_CANCEL;
            return true;
        }

        private void testFinished() {
            if (mGrid.isFinished() && mLine1.isFinished() && mLine2.isFinished()) {
                if (DeviceAttr.getRunningDeviceAttr().isExistETP() && !isETP) {
                    DebugLog.d("testFinished---reset!");
                    isETP = true;
                    parentContainer.removeAllViews();
                    TouchPanelView mTouchPanelView = new TouchPanelView(mContext, layoutWidth, layoutHeight);
                    parentContainer.addView(mTouchPanelView);
/*                    mGrid.mList.clear();
//                    AppExecutors.runOnIoThread(() -> {
                    addGrids();
//                    mGrid.reset();
                    mLine1.reset();
                    mLine2.reset();
                    invalidate();
//                    });
//                    invalidate();*/
                    showInfo();
                    einkPWInterface = EinkUtils.getEinkPWInterfaceWithView(mTouchPanelView);
                    if (einkPWInterface != null) {
                        einkPWInterface.enableTouchDispatch(2);
                        einkPWInterface.setEinkEraseA2Gate(255);
                    }
                } else {
                    finishWithOK();
                }
            }
        }
    }

    private void showInfo() {
        String useTool = getString(R.string.tp_test_use_finger);
        if (isETP) {
            useTool = getString(R.string.tp_test_use_electric_pen);
            imgUseTool.setImageResource(R.drawable.ic_pen);
        }
        String info = getString(R.string.tp_test_info2, useTool);
        txtInfo.setText(info);
        showToast(useTool);
    }

/*    private ServiceConnection serviceConnection = new MyServiceConnection();
    private FTFloatWindowService mBindService;

    private class MyServiceConnection implements ServiceConnection {

        @Override
        public void onServiceConnected(ComponentName name, IBinder binder) {

            FTFloatWindowService.MyBinder mBinder = (FTFloatWindowService.MyBinder) binder;
            mBindService = mBinder.getService();

            if (mBindService != null) {
                mBindService.setFloatLayoutVisibility(View.INVISIBLE);
            }

        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            mBindService = null;
        }

    }*/

    @Override
    int getLayoutId() {
        return R.layout.activity_factory_second;
    }

    @Override
    void onInitView(@Nullable Bundle savedInstanceState) {
        isETP = !DeviceAttr.getRunningDeviceAttr().isExistTP();

//        Intent intent = new Intent(this, FTFloatWindowService.class);
//        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
        parentContainer = findViewById(R.id.touch_draw_root_layout);

        // 监听布局完成事件
        parentContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                // 移除监听器，确保只调用一次
                parentContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                // 获取布局宽度和高度
                layoutWidth = parentContainer.getWidth();
                layoutHeight = parentContainer.getHeight();

                // 打印布局宽度和高度
                DebugLog.d("布局宽度: " + layoutWidth + ", 布局高度: " + layoutHeight);
            }
        });

        DebugLog.d("parentContainer width = " + layoutWidth + " height = " + layoutHeight);
        TouchPanelView mTouchPanelView = new TouchPanelView(this, layoutWidth, layoutHeight);
        EinkUtils.setEinkUpdateModeWithView(mTouchPanelView, EinkShowMode.DU);
//        setContentView(mTouchPanelView);
        parentContainer.addView(mTouchPanelView);
        txtInfo = findViewById(R.id.txtInfo);
        imgUseTool = findViewById(R.id.imgUseTool);
        imgUseTool.setVisibility(View.VISIBLE);
    }

    @Override
    void onHandleMessage(Handler handler, Message msg) {

    }

    @Override
    protected void onResume() {
        super.onResume();

        showInfo();

//        if (mBindService != null) {
//            mBindService.setFloatLayoutVisibility(View.INVISIBLE);
//        }

    }

    @Override
    protected void onPause() {
        super.onPause();

//        if (mBindService != null) {
//            mBindService.setFloatLayoutVisibility(View.VISIBLE);
//        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

//        unbindService(serviceConnection);
    }

}
